package com.techwells.learningkites.adapter;

import java.io.Serializable;
import java.util.List;

import com.lidroid.xutils.BitmapUtils;
import com.techwells.learningkites.R;
import com.techwells.learningkites.networkaccess.KitesRequestUrl;
import com.techwells.learningkites.networkservice.model.Comment;
import com.techwells.learningkites.networkservice.model.VideoCategory;
import com.techwells.learningkites.networkservice.model.CourseCategory;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class CommentListAdapter extends BaseAdapter {
	
	private Context mContext;
	private LayoutInflater mInflater;
	private List<Comment> mList;
	
	private BitmapUtils bitmapUtils;

	
	public CommentListAdapter(Context mContext, List<Comment> mList) {
		super();
		this.mContext = mContext;
		mInflater =(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.mList = mList;
		bitmapUtils = new BitmapUtils(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CellHolder cellHolder;
        if (convertView == null) {
        	cellHolder = new CellHolder();
        		convertView = mInflater.inflate(R.layout.item_commentlist, null);
        		cellHolder.user = (TextView) convertView.findViewById(R.id.user);
        		cellHolder.submit = (TextView) convertView.findViewById(R.id.submit_time);
        		cellHolder.comment = (TextView) convertView.findViewById(R.id.comment);
        		cellHolder.ratingBar = (RatingBar) convertView.findViewById(R.id.ratingbar);
                convertView.setTag(cellHolder);

        } else {
        	cellHolder = (CellHolder) convertView.getTag();
        }  
        
        if (mList.get(position).user.nickName != null) {
        	cellHolder.user.setText(mList.get(position).user.nickName);
		}else {
			cellHolder.user.setText("匿名");
		}
        
        cellHolder.submit.setText("发表于"+mList.get(position).submitTime);
        cellHolder.comment.setText(mList.get(position).comment);
        cellHolder.ratingBar.setRating(mList.get(position).rating);
       
		return convertView;
	}

	
	public static class CellHolder implements Serializable{
    	TextView user,submit,comment;
    	RatingBar ratingBar;
    }
}
